package jcn2000;

import java.lang.Math;
import jcn2000.AllocationContainer;
import jcn2000.JCN2000;

public class tacClient {
  public int pArrive=-1;
  public int pDepart=-1;
  public int cArrive=-1;
  public int cDepart=-1;
  public int expHVal=-1;
  public int enAWVal=-1;
  public int enMUVal=-1;
  public int enAPVal=-1;
  public int hotelType=-1;
  public int pValue  =-1;
  public int cValue  =-1;
  public int entAWD = -1;
  public int entAPD = -1;
  public int entMUD = -1;
  public int pEntValue = 0;
  public int cEntValue = 0;
  public boolean isParticipating=false;
  
  public tacClient() {
    clear();
  }

  //reset function
  public void clear() {
    pArrive=-1;
    pDepart=-1;
    expHVal=-1;
    enAWVal=-1;
    enMUVal=-1;
    enAPVal=-1;
    pValue  =-1;
    clearSettings();
  }

  public void clearSettings() {
    cArrive=-1;
    cDepart=-1;
    hotelType=-1;
    cValue  =-1;
    pEntValue = 0;
    cEntValue = 0;
    isParticipating = true;
  }

  public boolean haveOptimalTime(AllocationContainer[] allocations) {
    if (allocations[JCN2000.INFLIGHT].getInventory(pArrive) > 0 && allocations[JCN2000.OUTFLIGHT].getInventory(pDepart) > 0){
      for (int i=0; i<5; i++){
        if (allocations[JCN2000.EXPENSIVE_HOTEL].getInventory(i) < 1){
          return false;
        }
      }
      return true;
    }
    else {
      return false;
    }
  }
  
  //utility without entertainment
  public int utility(int arrive, int depart, int hotelType){
    return 1000 - (100*(Math.abs(arrive-pArrive) + Math.abs(depart-pDepart))) + (hotelType == JCN2000.EXPENSIVE_HOTEL ? 1: 0)*expHVal;
  }

  /*
  utility with entertainment
  (the last int is the sum of the utility constants, So you call this like: 
  client.utility(1,3,tacClient.CHEAP_HOTEL, tacClient.ENT_AW + tacClient.ENT_MU)
                                                            ^^^               */
  public int utility(int arrive, int depart, int hotelType, boolean AW, boolean AP, boolean MU){
    int funBonus = 0;
    if (AP){
      funBonus += enAPVal;
    }
    if (MU){
      funBonus += enMUVal;
    }
    if (AW){
      funBonus += enAWVal;
    }
    return 1000 - (100*(Math.abs(arrive-pArrive) + Math.abs(depart-pDepart))) + (hotelType == JCN2000.EXPENSIVE_HOTEL ? 1: 0)*expHVal + funBonus;
  }
  
  /*
  The Value they are worth to us (relative to each other, any constants are left
  outside the calculation)
  */
  //FIXME: this can be as advanced as we want, ATM it's a simple function that only 
  //needs to be run at the start we could add updating information, making this list
  //a better reflection.
  public int worth(){
    return (enAWVal+enMUVal+enAPVal+expHVal)/(pArrive - pDepart);
  }
  
  //Explanation of the reason we do what we do
  public String explanation(){
    String expl = "";
    expl += "hotelPenalty=\'"+(100*(Math.abs(cArrive-pArrive) + Math.abs(cDepart-pDepart)))+"\' ";
    expl += "hotelBonus=\'"+((hotelType == JCN2000.EXPENSIVE_HOTEL ? 1: 0)*expHVal)+"\' ";
    expl += "pEntValue=\'"+pEntValue+"\' ";
    expl += "cEntValue=\'"+cEntValue+"\' ";
    expl += "pValue=\'"+pValue+"\' ";
    return expl;
  }
}
